package summary;

import java.util.Stack;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/6 17:27
 * https://leetcode.cn/problems/daily-temperatures/
 */
public class Title739 {

    public static int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length;
        int[] result = new int[n];
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < n; i++) {
            while (!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]) {
                Integer left = stack.pop();
                result[left] = i - left;
            }
            stack.push(i);
        }
        return result;
    }

    public static void main(String[] args) {
        int[] arr = {73,74,75,71,69,72,76,73};
        dailyTemperatures(arr);
    }
}
